package org.example.buffer;

import java.nio.IntBuffer;

/**
 * 缓冲区
 * <p>异步时读取缓冲读写数据,解偶BIO中的读写阻塞操作</p>
 */
public class Demo1 {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(5);
        //写入
        for (int i = 0; i < intBuffer.capacity() ; i++) {
            intBuffer.put(i * 2);
        }
        //读写转换
        intBuffer.flip();
        //读取
        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }
    }
}
